'use strict';

const Service = require('egg').Service;

class WebService extends Service {
  async find() {
    return await this.ctx.model.Webpage.findAll();
  }

  async add(webpage) {
    return await this.ctx.model.Webpage.create(webpage);
  }

  async edit(webpage) {
    return await this.ctx.model.Webpage.update(webpage, {
      where: {
        id: webpage.id,
      },
    });
  }

  async show(cat_id, wid) {
    return await this.ctx.model.Webpage.findOne({
      where: {
        category_id: cat_id,
        id: wid,
      },
    });
  }

  async delete(wid) {
    return await this.ctx.model.Webpage.destroy({
      where: {
        id: wid,
      },
    });
  }
}

module.exports = WebService;
